
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        class Car {
            constructor(options){
                this.newOptions = options;
            }   
            
            change () {
                setInterval(() => {
                    this.options.time = new Date().getTime();
                }, 1000);
            }
            on (type, callback) {
                if(type === 'time') {
                    this.options = new Proxy(this.newOptions, {
                        get(target, property){
                           
                        },
                        set(target, property, value){
                            if(property === 'time'){
                                callback(value);
                            }
                            return value;
                        }
                    })
                }
            }
        }
        
        let car = new Car({time: 1});
        
        car.on('time', (val) => {
            console.log('val', val); 
        }); 
        
        car.change();
    </script>
</body>
</html>